package com.pgeneral.user.management.controller;

import com.pgeneral.user.management.config.ResultBean;
import com.pgeneral.user.management.dto.GlobalInfosDTO;
import com.pgeneral.user.management.entity.UserUserInfo;
import com.pgeneral.user.management.service.UserUserinfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户表
 *
 * @author lenovo
 */
@Slf4j
@RestController
@RequestMapping("/user/userInfo")
public class UserUserInfoController {

    @Autowired
    private UserUserinfoService service;

    /**
     * 查询用户,包括全部用户
     *
     * @param userInfo
     * @return
     */
//    @LogAnnotation(module="/user/sopScopeData",operator = "/getInfo 查询用户,包括全部用户")
    @PostMapping(value = "/getInfo")
    public ResultBean getUserInfo(@RequestBody UserUserInfo userInfo) {
        log.info("查询用户,包括全部用户");
        List<UserUserInfo> userUserInfo = service.getUserInfo(userInfo);
        return ResultBean.Success(userUserInfo);
    }

    /**
     * 添加用户信息
     *
     * @param userInfos
     * @return
     */
    @PostMapping(value = "/saveInfo")
    public ResultBean insertUserInfoTable(@RequestBody List<UserUserInfo> userInfos) {
        log.info("调用用户save方法，方法参数为：{}", userInfos);
        int result = service.batchInsert(userInfos);
        return ResultBean.InsertSuccessResult(result);
    }

    /**
     * 用户更新
     *
     * @param userInfos
     * @return
     */
    @RequestMapping(value = "/updateInfo", method = RequestMethod.POST)
    public ResultBean updateUserInfoTable(@RequestBody UserUserInfo userInfos) {
        log.info("：{}", userInfos);
        int result = service.updateUserInfoTable(userInfos);
        return ResultBean.InsertSuccessResult(result);

    }

    /**
     * 用户删除
     *
     * @param ids
     * @return
     */
    @RequestMapping(value = "/deleteInfo", method = RequestMethod.POST)
    public ResultBean deleteUserInfoTable(@RequestBody List<String> ids) {
        log.info("调用用户delete方法，方法参数为：{}", ids);
        int result = service.updateIsDeletefromUserInfoTable(ids);
        return ResultBean.InsertSuccessResult(result);
    }

    /**
     * 五表联查
     *
     * @return
     */
    @RequestMapping(value = "/getInfos", method = RequestMethod.POST)
    public ResultBean getGlobalInfos(@RequestBody UserUserInfo userInfo) {
        log.info("调用五表联查方法,用户表，角色表，科室表，权限表，权限角色关系表");
        List<GlobalInfosDTO> globalInfosDTOS = service.getGlobalInfos(userInfo);
        return ResultBean.Success(globalInfosDTOS);
    }

    /**
     * 根据用户UserID修改用户登录密码
     */
    @RequestMapping(value = "/updatePasswordByUserId", method = RequestMethod.POST)
    public ResultBean updatePassWordFromUserTableByUserId(@RequestBody UserUserInfo userInfo) {
        log.info("调用根据userId修改密码的方法");
        int i = service.updatePasswordByUserId(userInfo);
        return ResultBean.InsertSuccessResult(i);
    }

    /**
     * 三表联查
     */
    @RequestMapping(value = "/getThreeInfos", method = RequestMethod.POST)
    public ResultBean getThreeTable(@RequestBody UserUserInfo userInfo) {
        log.info("调用三表联查方法用户表，角色表，科室表，");
        List<GlobalInfosDTO> getThreeTable = service.getThreeTable(userInfo);
        return ResultBean.Success(getThreeTable);
    }

    /**
     * 五表联查为登录写
     *
     * @return
     */
    @RequestMapping(value = "/getLoginUserInfo", method = RequestMethod.POST)
    public ResultBean getLoginUser(@RequestBody UserUserInfo userInfo) {
        log.info("调用登录接口五表联查方法,用户表，角色表，科室表，权限表，权限角色关系表,{}", userInfo);
        List<GlobalInfosDTO> globalInfosDTOS = service.getLoginUser(userInfo);
        return ResultBean.Success(globalInfosDTOS);
    }

    /**
     * 查询用户签名地址
     *
     * @param userId
     * @return
     */
    @GetMapping(value = "/getSign")
    public ResultBean getSign(@RequestParam(value = "userId", required = false) String userId,
                              @RequestParam(value = "userName", required = false) String userName) {
        log.info("调用用户get方法，方法参数为：{},{}", userId, userName);
        List<UserUserInfo> lists = service.getSign(userId, userName);
        return ResultBean.Success(lists);
    }

    /**
     * 查询多名用户签名地址
     *
     * @param userName
     * @return
     */
    @PostMapping(value = "/getSignByUserNames")
    public ResultBean getSignByUserNames(@RequestBody List<String> userName) {
        log.info("调用用户get方法，方法参数为：{}", userName);
        List<UserUserInfo> lists = service.getSignByUserNames(userName);
        return ResultBean.Success(lists);
    }
}
